home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 2.iso / STUTTGART / TEMP / GNU / bison / GrammarinB < prev    next >
Text File  |  1995-06-28  |  2KB  |  44 lines

  1. Grammar in Bison
  2. Previous: <Language and Grammar=>Languagean> * Next: <Semantic Values=>SemanticVa> * Up: <Concepts=>Concepts>
  3.  
  4. #Wrap on
  5. {fH3}From Formal Rules to Bison Input{f}
  6.  
  7. A formal grammar is a mathematical construct.  To define the language
  8. for Bison, you must write a file expressing the grammar in Bison syntax:
  9. a {fUnderline}Bison grammar{f} file.  \*Note <Grammar File=>GrammarFil>: Bison Grammar Files.
  10.  
  11. A nonterminal symbol in the formal grammar is represented in Bison input
  12. as an identifier, like an identifier in C.  By convention, it should be
  13. in lower case, such as {fCode}expr{f}, {fCode}stmt{f} or {fCode}declaration{f}.
  14.  
  15. The Bison representation for a terminal symbol is also called a {fUnderline}token
  16. type{f}.  Token types as well can be represented as C-like identifiers.  By
  17. convention, these identifiers should be upper case to distinguish them from
  18. nonterminals: for example, {fCode}INTEGER{f}, {fCode}IDENTIFIER{f}, {fCode}IF{f} or
  19. {fCode}RETURN{f}.  A terminal symbol that stands for a particular keyword in
  20. the language should be named after that keyword converted to upper case.
  21. The terminal symbol {fCode}error{f} is reserved for error recovery.
  22. \*Note <Symbols=>Symbols>.
  23.  
  24. A terminal symbol can also be represented as a character literal, just like
  25. a C character constant.  You should do this whenever a token is just a
  26. single character (parenthesis, plus-sign, etc.): use that same character in
  27. a literal as the terminal symbol for that token.
  28.  
  29. The grammar rules also have an expression in Bison syntax.  For example,
  30. here is the Bison rule for a C {fCode}return{f} statement.  The semicolon in
  31. quotes is a literal character token, representing part of the C syntax for
  32. the statement; the naked semicolon, and the colon, are Bison punctuation
  33. used in every rule.
  34.  
  35. #Wrap off
  36. #fCode
  37. stmt:   RETURN expr ';'
  38.         ;
  39. #f
  40. #Wrap on
  41.  
  42. \*Note <Rules=>Rules>: Syntax of Grammar Rules.
  43.  
  44.